<?xml version="1.0" encoding="UTF-8"?>
<!--
  - Copyright 2012 Google Inc.
  -
  - Licensed under the Apache License, Version 2.0 (the "License"); you may not
  - use this file except in compliance with the License. You may obtain a copy
  - of the License at
  -
  - http://www.apache.org/licenses/LICENSE-2.0
  -
  - Unless required by applicable law or agreed to in writing, software
  - distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  - WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  - License for the specific language governing permissions and limitations
  - under the License.
-->
<project name="CEPAppEngine" default="dist">

  <!-- Set the Google App Engine SDK location below or using -Dsdk.dir -->
  <!--
  <property name="sdk.dir" location="/opt/google/appengine-java-sdk" />
  -->
  <!-- Also set the property below to your server's host name or ip address -->
  <property name="server.host" value="localhost"/>
  <property name="server.port" value="8888"/>
  <property name="sdk.dir" value ="C:/Eclipse/eclipse/plugins/com.google.appengine.eclipse.sdkbundle_1.7.0/appengine-java-sdk-1.7.0"/>
  
  <import file="${sdk.dir}/config/user/ant-macros.xml" />
  
  <property name="src" location="src"/>
  <property name="lib" location="${web-inf}/lib"/>
  <property name="build" location="build"/>
  <property name="dist" location="dist"/>
  <property name="war" value="${dist}/cep-app-engine.war"/>
  <property name="web-src" value="war"/>
  <property name="web-inf" value="${web-src}/WEB-INF"/>
  <property name="web-lib" value="${web-inf}/lib"/>
  <property name="classes" location="${web-inf}/classes"/>
  <target name="default" depends="dist"/>
  
  <path id="project.classpath" >
        <pathelement path="${classes}" />
        <fileset dir="war/WEB-INF/lib" >
            <include name="**/*.jar" />
        </fileset>
        <fileset dir="${sdk.dir}/lib" >
            <include name="shared/**/*.jar" />
        </fileset>
    </path>
  
 <target name="copyjars" depends="init"
      description="Copies the App Engine JARs to the WAR." if="sdk.dir">
    <copy
        todir="${lib}"
        flatten="true">
      <fileset dir="${sdk.dir}/lib/user">
        <include name="**/*.jar" />
      </fileset>
    </copy>
  </target>
  
  <target name="compile" depends="copyjars"
      description="Compiles Java source and copies other source files to the WAR.">
    <mkdir dir="${classes}" />
    <copy todir="${classes}">
      <fileset dir="src">
        <exclude name="**/*.java" />
      </fileset>
    </copy>
    <javac
        srcdir="src"
        destdir="${classes}"
        classpathref="project.classpath"
        debug="on" />
  </target>
  
  <target name="datanucleusenhance" depends="compile"
      description="Performs JDO enhancement on compiled data classes.">
    <enhance_war war="${web-src}" />
  </target>
  
  <target name="runserver" depends="datanucleusenhance"
      description="Starts the development server.">
    <dev_appserver war="${web-src}" port="${server.port}" >
    </dev_appserver>
  </target>
  <target name="update" depends="datanucleusenhance"
      description="Uploads the application to App Engine.">
    <appcfg action="update" war="war" />
  </target>

  <target name="update_indexes" depends="datanucleusenhance"
      description="Uploads just the datastore index configuration to App Engine.">
    <appcfg action="update_indexes" war="${web-src}" />
  </target>

  <target name="rollback" depends="datanucleusenhance"
      description="Rolls back an interrupted application update.">
    <appcfg action="rollback" war="${web-src}" />
  </target>

  <target name="request_logs"
      description="Downloads log data from App Engine for the application.">
    <appcfg action="request_logs" war="${web-src}">
      <options>
        <arg value="--num_days=5"/>
      </options>
      <args>
        <arg value="logs.txt"/>
      </args>
    </appcfg>
  </target>
  <target name="init">
    <mkdir dir="${classes}"/>
    <mkdir dir="${dist}"/>
  </target>

  <!-- You can give the development server arguments using attributes and an <options> element.
       For example, the following target starts the server using the port 8888,
       and enables remote Java debugging on port 9999:
  -->
  <target name="debugserver" depends="datanucleusenhance" description="Starts the development server on debug mode.">
    <dev_appserver war="${web-src}" port="${server.port}" address="${server.host}">
      <options>
        <arg value="--jvm_flag=-Xdebug"/>
        <arg value="--jvm_flag=-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=9999"/>
      </options>
    </dev_appserver>
  </target>
  
  <target name="war" depends="datanucleusenhance" description="Generate the WAR file.">
    <war destfile="${war}" webxml="${web-src}/WEB-INF/web.xml">
      <fileset dir="${web-src}"/>
      <classes dir="${classes}"/>
    </war>
  </target>
<target name="dist" depends="war" description="Generate all artifacts."/>
</project>

